package com.rxt.thermopro.viewmodel

import com.app.common.viewmodel.BaseViewModel
import com.app.common.viewmodel.EventLiveData
import com.rxt.thermopro.app.LocalDataDao
import com.rxt.thermopro.bean.ProbeHistoryWrapper

class HistoryViewModel : BaseViewModel() {

    val historyList: EventLiveData<MutableList<ProbeHistoryWrapper>> = EventLiveData()

    fun getHistory(address: String) {
        val list1 = LocalDataDao.INSTANCE.getProbeHistoryList(address, 0)
        val list2 = LocalDataDao.INSTANCE.getProbeHistoryList(address, 1)
        val list3 = LocalDataDao.INSTANCE.getProbeHistoryList(address, 2)
        val list4 = LocalDataDao.INSTANCE.getProbeHistoryList(address, 3)

        val totalList = mutableListOf<ProbeHistoryWrapper>()
        totalList.addAll(list1)
        totalList.addAll(list2)
        totalList.addAll(list3)
        totalList.addAll(list4)
        totalList.sortByDescending { it.lastTime.toLong() }

        historyList.value = totalList
    }

    fun removeHistory(item: ProbeHistoryWrapper) {
        LocalDataDao.INSTANCE.deleteHistory(item)
    }

}